package codewars.arrays;

import java.util.stream.IntStream;

/**
 * Find the missing letter
 * CodeWars: https://www.codewars.com/kata/find-the-missing-letter/train/java
 * Topics: algorithms, mathematics, numbers
 *
 * 给一个连续增长的char数组，找到其中缺失的char 符号
 *
 * Created by yzy on 2019-05-11 16:46
 */
public class FindTheMissingLetter {

    public static void main(String[] args) {
        char[] arr = new char[]{'a','b','c','d','f'};
        System.out.println(findMissingLetter(arr));
    }

    public static char findMissingLetter(char[] array){
        for(int i=0; i<array.length-1; i++){
            if(array[i+1] - array[i] != 1){
                return (char) (array[i] +1);
            }
        }

        return ' ';
    }

    public static char findMissingLetter_lambda(char[] array){
        int idx = IntStream.range(0, array.length-1).filter(i -> array[i] !=array[i+1]-1).findFirst().getAsInt();
        return (char)(array[idx]+1);
    }
}
